﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace Domain
{
    /// <summary>
    /// Категория участников гонки
    /// </summary>
    public class Category: INotifyPropertyChanged
    {
        private String _name;

        /// <summary>
        /// Название категории
        /// </summary>
        public String Name
        {
            get { return _name; }
            set
            {
                bool changed = value != _name;
                _name = value;
                if (changed) InvokePropertyChanged(new PropertyChangedEventArgs("Name"));
            }
        }

        /// <summary>
        /// Список гонщиков этой категории
        /// </summary>
        public ObservableCollection<Racer> Racers { get; private set; }

        public Category(String name)
        {
            Name = name;
            Racers = new ObservableCollection<Racer>();
        }

        /// <summary>
        /// Добавть гонщика в категорию
        /// </summary>
        /// <param name="racer">Гонщик</param>
        public void AddRacer(Racer racer)
        {
            racer.Category = this;
        }

        /// <summary>
        /// Удалить гонщика из категории
        /// </summary>
        /// <param name="racer">Гонщик</param>
        public void RemoveRacer(Racer racer)
        {
            racer.Category = null;
        }

        #region Implementation of INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        public void InvokePropertyChanged(PropertyChangedEventArgs e)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, e);
        }

        #endregion
        
    }
}
